/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ejb;

import bean.RptPensionesMaternal;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author cesardoncel
 */
@Stateless
public class RptPensionesMaternalFacade extends AbstractFacade<RptPensionesMaternal> {
    @PersistenceContext(unitName = "escuelaMaternalPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public RptPensionesMaternalFacade() {
        super(RptPensionesMaternal.class);
    }
    
    public RptPensionesMaternal findById (String id){
        try {            
            Query q = em.createNamedQuery("RptPensionesMaternal.findByIduDocumento");
            q.setParameter("iduDocumento", id);
            RptPensionesMaternal r = new RptPensionesMaternal();
            r = (RptPensionesMaternal) q.getSingleResult();
            em.refresh(r);
            return r;
        }
        catch (Exception e){
            System.err.println("Error encontrando RptPensionesMaternal. " + e.getLocalizedMessage());
            return null;
        }  
    }
    
    public List<RptPensionesMaternal> findByDocEstudiante(String documento){
        try {  
            Query q = em.createNamedQuery("RptPensionesMaternal.findByDocEstudiante");
            q.setParameter("docEstudiante", documento);
            List<RptPensionesMaternal> registros = new ArrayList<RptPensionesMaternal>();
            registros.addAll(q.getResultList());
            return registros;
        }
        catch (Exception e){
            System.err.println("Error encontrando RptPensionesMaternal por documento " + documento + " => " + e.getLocalizedMessage());
            return null;
        }
    }
}
